package logic

import (
	"context"
	"encoding/json"
	"fmt"
	"time"
	"video-guard/models/cache"
	"video-guard/models/mysql"

	"video-guard/videorpc/internal/svc"
	"video-guard/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoShowLogic {
	return &VideoShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VideoShowLogic) VideoShow(in *videorpc.VideoShowTRequest) (*videorpc.VideoShowTResponse, error) {
	// todo: add your logic here and delete this line
	show := mysql.VideoShow(mysql.DB)
	marshal, _ := json.Marshal(show)
	sprintf := fmt.Sprintf("video%d", in.VideoId)
	cache.Rdb.Set(cache.Ctx, sprintf, marshal, time.Minute*10)
	return &videorpc.VideoShowTResponse{
		Title:         show.Title,
		VideoCategory: show.VideoCategory,
		CoverLink:     show.CoverLink,
		VideoIntro:    show.VideoIntro,
		VideoStatus:   show.VideoStatus,
		LikeNum:       show.LikeNum,
		CommentNum:    show.CommentNum,
		CollectNum:    show.CollectNum,
		PlayNum:       show.PlayNum,
		NickName:      show.NickName,
		AvatarLink:    show.AvatarLink,
		TopicName:     show.TopicName,
		TopicIntro:    show.TopicIntro,
	}, nil
}
